#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 19-6-2 下午7:08
# @Author  : Tom
# @Site    : 
# @File    : breadcrumb.py
# @Software: PyCharm


# 获取面包屑
def get_breadcrumb(category):
    '''获取面包屑导航
    :param category: 商品类别
    :return: 面包屑导航字典
    '''
    cat2 = category.parent
    cat1 = cat2.parent
    breadcrumb = {
        'cat1': {
            'url': cat1.goodschannel_set.all()[0].url,
            'name': cat1.name
        },
        'cat2': cat2,
        'cat3': category,
    }
    return breadcrumb

    # breadcrumb = dict(
    #     cat1='',
    #     cat2='',
    #     cat3='',
    # )
    # # 当前为空，则为第一级广告分类
    # if category.parent is None:
    #     breadcrumb['cat1'] = category
    # # 当前为空，则为第三级广告分类
    # elif category.subs.count() == 0:
    #     breadcrumb['cat3'] = category
    #     breadcrumb['cat2'] = category.parent
    #     breadcrumb['cat1'] = category.parent.parent
    # else:
    #     # 当前为空，则为第二级广告分类
    #     breadcrumb['cat2'] = category
    #     breadcrumb['cat1'] = category.parent
    #
    # return breadcrumb
